/************************************************************************/
/* Game                                                                 */
/************************************************************************/
#include "Game/Game Objects/Towers/Shots/StandardShot.h"

namespace TD_Game {

	/************************************************************************/
	/* ctors and dtors                                                      */
	/************************************************************************/
	StandardShot::StandardShot() {
		
	}

	StandardShot::StandardShot(const StandardShot &rhs) {

	}

	StandardShot & StandardShot::operator =(const StandardShot &rhs) {
		BaseEntity::operator =(rhs);
		return(*this);
	}

	StandardShot::StandardShot(const Coord2D &initialPosition, unsigned int g_shotDamage, const BaseMario *targetMario, unsigned int marioID, shotTypes shotType) 
		: BaseShot(initialPosition, g_shotDamage, targetMario, marioID) {
		m_pAnimationSet = AnimationSetFactory::createShotAnimationSet(shotType, "Moving");
		m_shotType = shotType;
		m_shapes.push_back(new RectangleShape(m_position, m_pAnimationSet->getSprites()->getTilesize()));
		switch(m_shotType) {
			case pelletShot_lvl1:
			case pelletShot_lvl2:
			case pelletShot_lvl3:
			case pelletShot_lvl4:
			case pelletShot_lvl5:
			case pelletShot_lvl6:
				m_pLaunchSound = TD_Resources::ResourceManager::loadSound("SFX/sounds/shyguyshot.wav");
				m_pHittedSound =  TD_Resources::ResourceManager::loadSound("SFX/sounds/shyguyhit.wav");
				m_pLaunchSound->playSound(false);
			break;


			case fireShot_lvl1:
			case fireShot_lvl2:
			case fireShot_lvl3:
			case fireShot_lvl4:
			case fireShot_lvl5:
			case fireShot_lvl6:
				m_pLaunchSound = TD_Resources::ResourceManager::loadSound("SFX/sounds/fireTowerLaunch.wav");
				m_pHittedSound =  TD_Resources::ResourceManager::loadSound("SFX/sounds/fireTowerHit.wav");
				m_pLaunchSound->playSound(false);
			break;

			case spineShell_lvl1:
			case spineShell_lvl2:
			case spineShell_lvl3:
			case spineShell_lvl4:
			case spineShell_lvl5:
			case spineShell_lvl6:
				m_pHittedSound =  TD_Resources::ResourceManager::loadSound("SFX/sounds/unaway.wav");
			break;
			
			case magikoopaShot_lvl1:
			case magikoopaShot_lvl2:
			case magikoopaShot_lvl3:
			case magikoopaShot_lvl4:
			case magikoopaShot_lvl5:
			case magikoopaShot_lvl6:
				m_pLaunchSound = TD_Resources::ResourceManager::loadSound("SFX/sounds/magikoopaShot.wav");
				m_pHittedSound = TD_Resources::ResourceManager::loadSound("SFX/sounds/magikoopahit.wav");
				m_pLaunchSound->playSound(false);
			break;

			case iceShot_lvl1:
			case iceShot_lvl2:
			case iceShot_lvl3:
			case iceShot_lvl4:
			case iceShot_lvl5:
			case iceShot_lvl6:
				m_pLaunchSound = TD_Resources::ResourceManager::loadSound("SFX/sounds/snifitShot.wav");
				m_pHittedSound = TD_Resources::ResourceManager::loadSound("SFX/sounds/snifitHit.wav");
				m_pLaunchSound->playSound(false);
			break;
		}
		

	}

	StandardShot::~StandardShot() {
		
	}

	void StandardShot::hitTarget() {
		vector<BaseMario *> marios;
		switch(m_shotType) {
			case pelletShot_lvl1:
			case pelletShot_lvl2:
			case pelletShot_lvl3:
			case pelletShot_lvl4:
			case pelletShot_lvl5:
			case pelletShot_lvl6:
			case spineShell_lvl1:
			case spineShell_lvl2:
			case spineShell_lvl3:
			case spineShell_lvl4:
			case spineShell_lvl5:
			case spineShell_lvl6:

			case magikoopaShot_lvl1:
			case magikoopaShot_lvl2:
			case magikoopaShot_lvl3:
			case magikoopaShot_lvl4:
			case magikoopaShot_lvl5:
			case magikoopaShot_lvl6:
				if(MarioManager::getInstance()->getMarioByID(m_marioID) != NULL) {
					m_pTargetMario->receiveDamage(m_shotDamage);
				} 
				m_pHittedSound->playSound(false);
			break;

			case fireShot_lvl1:
			case fireShot_lvl2:
			case fireShot_lvl3:
			case fireShot_lvl4:
			case fireShot_lvl5:
			case fireShot_lvl6:
				marios = MarioManager::getInstance()->getMariosWithinRadius(m_position, 100);
				if(marios.size() > 0) {
					for(unsigned int i = 0; i < marios.size(); i++) {
						marios[i]->receiveDamage(m_shotDamage);
					}
				}
				m_pHittedSound->playSound(false);
			break;

			case iceShot_lvl1:
			case iceShot_lvl2:
			case iceShot_lvl3:
			case iceShot_lvl4:
			case iceShot_lvl5:
			case iceShot_lvl6:
				marios = MarioManager::getInstance()->getMariosWithinRadius(m_position, 60);
				
				if(MarioManager::getInstance()->getMarioByID(m_marioID) != NULL) {
					m_pTargetMario->receiveDamage(m_shotDamage);
				} 

				if(marios.size() > 0) {
					for(unsigned int i = 0; i < marios.size(); i++) {
						marios[i]->receiveDamage(m_shotDamage*0.6);
						marios[i]->addSlowDebuff(1000, 0.4);
					}
				}
				m_pHittedSound->playSound(false);
			break;

		}
		
	}
}